/*
 * All rights Reserved, Designed By www.goldbeacon.cn
 * @Title:  demo-springboot
 * @Package com.chenzhengrong.demospringboot.controlloer
 * @author: chenzhengrong
 * @date:   2022/8/16 14:11
 * @version V1.0
 * Copyright © 2022 www.goldbeacon.cn. All Rights Reserved.
 * 注意：本内容仅限于湖南金烽信息科技有限公司内部传阅，禁止外泄以及用于其他的商业目
 */
package com.chenzhengrong.demospringboot.controlloer;

import com.chenzhengrong.demospringboot.config.PlatformConfig;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author chenzhengrong
 * @title: HelloController
 * @description: hello
 * @date 2022/8/16 14:11
 */
@Slf4j
@Controller
public class HelloController {

    /*private Map<Long, User> userMap = new ConcurrentHashMap<>();

    @PutMapping("/putUser/{id}/")
    public User putUser(Long id, User user) {
        User put = userMap.put(id, user);
        log.info("userMap:{}",userMap);
        return put;
    }

    @PostMapping("/postUser")
    public User postUser(User user) {
        User user1 = new User();
        user1.setId(user.getId());
        user1.setName(user.getName());
        user1.setAge(user.getAge());
        return user1;
    }

    @DeleteMapping("/delUser/{id}")
    public User delUser(@PathVariable("id") Long id) {
        User put = userMap.remove(id);
        return put;
    }

    @GetMapping("/userList")
    public Map<Long, User> getUserList() {
        Set<Map.Entry<Long, User>> entries = userMap.entrySet();
        Iterator<Map.Entry<Long, User>> iterator = entries.stream().iterator();
        while (iterator.hasNext()) {
            Map.Entry<Long, User> next = iterator.next();
            log.info(" {},user: {}", next.getKey(), next.getValue() );
        }
        return userMap;
    }

    @GetMapping("/getUser/{id}")
    public User getUser(@PathVariable("id") Long id) {
        User user = userMap.get(id);
        return user;
    }*/

    @Autowired
    private PlatformConfig platformConfig;

    @GetMapping("/")
    @ResponseBody
    public String index(Model model) {
        model.addAttribute("platformConfig", platformConfig);
        log.info("index");
        return "hello 陈峥嵘";
    }

    @GetMapping("/index")
    public String index1(Model model) {
        model.addAttribute("platformConfig", platformConfig);
        log.info("index");
        return "/index";
    }


    @GetMapping("/hello")
    @ResponseBody
    public String hello() {
        log.info("hello SpringBoot");
        return "hello SpringBoot";
    }

    @GetMapping("/platform")
    @ResponseBody
    public PlatformConfig platform() {
        log.info("{}", platformConfig);
        return platformConfig;
    }

}
